package com.e3.sysmg.security.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.e3.core.base.SuperEntity;

@Entity
@Table(name="T_ROLE")
public class RoleEntity extends SuperEntity {

	private static final long serialVersionUID = 6800401924755069827L;

	private String code;
	
	private String name;
	
	private String description;
	
	private List<RoleEntity> parentRoles;
	
	private List<ModuleEntity> authedModules;
	
	@Column(name="CODE")
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name="NAME")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name="DESCRIPTION")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@ManyToMany(cascade=CascadeType.REFRESH,fetch=FetchType.LAZY)
	@JoinTable(name="T_ROLE_RELATION",joinColumns=@JoinColumn(name="ROLE_ID")
			,inverseJoinColumns=@JoinColumn(name="PARENT_ID"))
	public List<RoleEntity> getParentRoles() {
		return parentRoles;
	}

	public void setParentRoles(List<RoleEntity> parentRoles) {
		this.parentRoles = parentRoles;
	}

	@ManyToMany(cascade=CascadeType.REFRESH,fetch=FetchType.LAZY)
	@JoinTable(name="T_ROLE_MODULE",joinColumns=@JoinColumn(name="ROLE_ID")
			,inverseJoinColumns=@JoinColumn(name="MODULE_ID"))
	public List<ModuleEntity> getAuthedModules() {
		return authedModules;
	}

	public void setAuthedModules(List<ModuleEntity> authedModules) {
		this.authedModules = authedModules;
	}
	
}
